from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-08-31 14:04:11.832723
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 31, Aug, 2022
Time: 14:04:17
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.2671
Nobs: 765.000 HQIC: -50.6029
Log likelihood: 9756.58 FPE: 8.55454e-23
AIC: -50.8130 Det(Omega_mle): 7.61087e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.300856 0.054710 5.499 0.000
L1.Burgenland 0.106694 0.036384 2.932 0.003
L1.Kärnten -0.106799 0.019332 -5.524 0.000
L1.Niederösterreich 0.205919 0.076044 2.708 0.007
L1.Oberösterreich 0.114475 0.073712 1.553 0.120
L1.Salzburg 0.252652 0.038926 6.491 0.000
L1.Steiermark 0.035670 0.050792 0.702 0.483
L1.Tirol 0.106840 0.041123 2.598 0.009
L1.Vorarlberg -0.060704 0.035357 -1.717 0.086
L1.Wien 0.049301 0.065517 0.752 0.452
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.060029 0.113661 0.528 0.597
L1.Burgenland -0.034965 0.075589 -0.463 0.644
L1.Kärnten 0.047410 0.040163 1.180 0.238
L1.Niederösterreich -0.173803 0.157982 -1.100 0.271
L1.Oberösterreich 0.395344 0.153137 2.582 0.010
L1.Salzburg 0.290198 0.080869 3.589 0.000
L1.Steiermark 0.105154 0.105521 0.997 0.319
L1.Tirol 0.314291 0.085433 3.679 0.000
L1.Vorarlberg 0.026612 0.073455 0.362 0.717
L1.Wien -0.023012 0.136112 -0.169 0.866
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.191160 0.028135 6.794 0.000
L1.Burgenland 0.089614 0.018711 4.789 0.000
L1.Kärnten -0.008726 0.009942 -0.878 0.380
L1.Niederösterreich 0.259725 0.039106 6.642 0.000
L1.Oberösterreich 0.134669 0.037906 3.553 0.000
L1.Salzburg 0.045621 0.020018 2.279 0.023
L1.Steiermark 0.017624 0.026120 0.675 0.500
L1.Tirol 0.093774 0.021147 4.434 0.000
L1.Vorarlberg 0.058378 0.018182 3.211 0.001
L1.Wien 0.119248 0.033692 3.539 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.108547 0.028577 3.798 0.000
L1.Burgenland 0.047630 0.019005 2.506 0.012
L1.Kärnten -0.014771 0.010098 -1.463 0.144
L1.Niederösterreich 0.191988 0.039720 4.833 0.000
L1.Oberösterreich 0.290719 0.038502 7.551 0.000
L1.Salzburg 0.111420 0.020332 5.480 0.000
L1.Steiermark 0.102387 0.026530 3.859 0.000
L1.Tirol 0.110406 0.021480 5.140 0.000
L1.Vorarlberg 0.069549 0.018468 3.766 0.000
L1.Wien -0.018554 0.034222 -0.542 0.588
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.130376 0.051898 2.512 0.012
L1.Burgenland -0.051641 0.034514 -1.496 0.135
L1.Kärnten -0.040333 0.018339 -2.199 0.028
L1.Niederösterreich 0.169630 0.072136 2.352 0.019
L1.Oberösterreich 0.140799 0.069923 2.014 0.044
L1.Salzburg 0.287900 0.036925 7.797 0.000
L1.Steiermark 0.032396 0.048182 0.672 0.501
L1.Tirol 0.161942 0.039009 4.151 0.000
L1.Vorarlberg 0.100529 0.033540 2.997 0.003
L1.Wien 0.070331 0.062150 1.132 0.258
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.056262 0.041330 1.361 0.173
L1.Burgenland 0.040319 0.027486 1.467 0.142
L1.Kärnten 0.050430 0.014604 3.453 0.001
L1.Niederösterreich 0.221235 0.057446 3.851 0.000
L1.Oberösterreich 0.283180 0.055684 5.085 0.000
L1.Salzburg 0.046122 0.029406 1.568 0.117
L1.Steiermark -0.001411 0.038370 -0.037 0.971
L1.Tirol 0.147857 0.031065 4.760 0.000
L1.Vorarlberg 0.072686 0.026710 2.721 0.007
L1.Wien 0.084139 0.049493 1.700 0.089
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.179802 0.049497 3.633 0.000
L1.Burgenland -0.006001 0.032918 -0.182 0.855
L1.Kärnten -0.061204 0.017490 -3.499 0.000
L1.Niederösterreich -0.081978 0.068799 -1.192 0.233
L1.Oberösterreich 0.196228 0.066688 2.942 0.003
L1.Salzburg 0.056782 0.035217 1.612 0.107
L1.Steiermark 0.230260 0.045952 5.011 0.000
L1.Tirol 0.493604 0.037204 13.267 0.000
L1.Vorarlberg 0.047719 0.031988 1.492 0.136
L1.Wien -0.053045 0.059274 -0.895 0.371
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.166381 0.056828 2.928 0.003
L1.Burgenland -0.010414 0.037793 -0.276 0.783
L1.Kärnten 0.067174 0.020081 3.345 0.001
L1.Niederösterreich 0.206928 0.078988 2.620 0.009
L1.Oberösterreich -0.071029 0.076565 -0.928 0.354
L1.Salzburg 0.211454 0.040432 5.230 0.000
L1.Steiermark 0.115640 0.052758 2.192 0.028
L1.Tirol 0.071695 0.042714 1.678 0.093
L1.Vorarlberg 0.121553 0.036726 3.310 0.001
L1.Wien 0.122236 0.068053 1.796 0.072
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.359148 0.032817 10.944 0.000
L1.Burgenland 0.005707 0.021824 0.261 0.794
L1.Kärnten -0.023249 0.011596 -2.005 0.045
L1.Niederösterreich 0.214505 0.045613 4.703 0.000
L1.Oberösterreich 0.189920 0.044214 4.295 0.000
L1.Salzburg 0.046090 0.023349 1.974 0.048
L1.Steiermark -0.016531 0.030466 -0.543 0.587
L1.Tirol 0.106172 0.024666 4.304 0.000
L1.Vorarlberg 0.073279 0.021208 3.455 0.001
L1.Wien 0.046474 0.039299 1.183 0.237
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.040154 0.148259 0.192102 0.157529 0.123995 0.112821 0.065923 0.221613
Kärnten 0.040154 1.000000 -0.004049 0.132779 0.041274 0.095790 0.430939 -0.052239 0.100480
Niederösterreich 0.148259 -0.004049 1.000000 0.337448 0.150118 0.298717 0.107143 0.182971 0.322787
Oberösterreich 0.192102 0.132779 0.337448 1.000000 0.227445 0.330665 0.172027 0.167912 0.263925
Salzburg 0.157529 0.041274 0.150118 0.227445 1.000000 0.146831 0.122314 0.147682 0.132262
Steiermark 0.123995 0.095790 0.298717 0.330665 0.146831 1.000000 0.151243 0.138220 0.079154
Tirol 0.112821 0.430939 0.107143 0.172027 0.122314 0.151243 1.000000 0.115015 0.152232
Vorarlberg 0.065923 -0.052239 0.182971 0.167912 0.147682 0.138220 0.115015 1.000000 0.006736
Wien 0.221613 0.100480 0.322787 0.263925 0.132262 0.079154 0.152232 0.006736 1.000000